package com.hystrix.payment.controller;

import com.hystrix.payment.service.FeignPaymentService;
import com.hystrix.payment.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @Author：Administrator
 * @Date：2022/7/12/0012 23:08
 * @Versiion：1.0
 */
@RestController
@Slf4j
public class TestController {

    @Resource
    private FeignPaymentService feignPaymentService;
    @Resource
    private PaymentService paymentService;

    @GetMapping("/paymentOk")
    public String paymentOk(){
        String time = String.valueOf(System.currentTimeMillis());
        String paymentOk = feignPaymentService.paymentOk(time);
        log.info("paymentOk:{}",paymentOk);
        return paymentOk;
    }

    @GetMapping("/paymentTimeout")
    public String paymentTimeout(){
        String time = String.valueOf(System.currentTimeMillis());
        String paymentTimeout = feignPaymentService.paymentTimeout(time);
        log.info("paymentTimeout:{}",paymentTimeout);
        return paymentTimeout;
    }

    @GetMapping("/paymentOk1")
    public String paymentOk1(){
        String paymentOk = paymentService.paymentOk();
        log.info("paymentOk1:{}",paymentOk);
        return paymentOk;
    }

    @GetMapping("/paymentTimeout1")
    public String paymentTimeout1(){
        String paymentTimeout = paymentService.paymentTimeout();
        log.info("paymentTimeout1:{}",paymentTimeout);
        return paymentTimeout;
    }

    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") int id){
        log.info("========================>测试熔断");
        return paymentService.paymentCircuitBreaker(id);
    }

}
